import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";
import _map from "lodash/map";
import _join from "lodash/join";
import _isEmpty from "lodash/isEmpty";

var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _dec10, _dec11, _dec12, _dec13, _dec14, _dec15, _dec16, _dec17, _dec18, _dec19, _dec20, _dec21, _dec22, _dec23, _dec24, _dec25, _dec26, _dec27, _dec28, _dec29, _dec30, _dec31, _dec32, _dec33, _dec34, _class, _class2;

/**
 * 子账户管理-平台级
 * todo 角色，部分： 1。 别的公司管理员分配的角色怎么办
 * @date 2018-12-15

 */
import React from 'react';
import { Badge, Table, Tree } from 'antd';
import { connect } from 'dva';
import { Bind } from 'lodash-decorators';
import classnames from 'classnames';
import { Content, Header } from 'components/Page';
import ExcelExport from 'components/ExcelExport';
import { Button as ButtonPermission } from 'components/Permission';
import intl from 'utils/intl';
import formatterCollections from 'utils/intl/formatterCollections';
import { CPAAS_IAM } from 'utils/config';
import { dateRender, operatorRender } from 'utils/renderer';
import { getCurrentUser, tableScrollWidth, encryptPwd } from 'utils/utils';
import { DEFAULT_DATE_FORMAT } from 'utils/constants';
import notification from 'utils/notification';
import FilterForm from "./FilterForm";
import EditPasswordModal from "./components/EditPasswordModal";
import EditModal from "./components/EditModal";
import UserGroupModal from "./components/UserGroupModal";
import EmployeeModal from "./components/EmployeeModal";
var TreeNode = Tree.TreeNode;
var SubAccountSite = (_dec = connect(function (_ref) {
  var loading = _ref.loading,
      subAccount = _ref.subAccount,
      user = _ref.user;
  return {
    user: user,
    fetching: loading.effects['subAccount/fetchSubAccountList'],
    saving: loading.effects['subAccount/createSubAccount'] || loading.effects['subAccount/updateSubAccount'],
    passwordLoading: loading.effects['subAccount/updatePassword'],
    queryDetailLoading: loading.effects['subAccount/querySubAccount'],
    roleRemoveLoading: loading.effects['subAccount/removeRoles'],
    fetchEmployeeLoading: loading.effects['subAccount/queryEmployee'],
    currentUserId: (getCurrentUser() || {}).id,
    currentUser: getCurrentUser(),
    subAccount: subAccount
  };
}), _dec2 = formatterCollections({
  code: ['ciam.subAccount']
}), _dec3 = Bind(), _dec4 = Bind(), _dec5 = Bind(), _dec6 = Bind(), _dec7 = Bind(), _dec8 = Bind(), _dec9 = Bind(), _dec10 = Bind(), _dec11 = Bind(), _dec12 = Bind(), _dec13 = Bind(), _dec14 = Bind(), _dec15 = Bind(), _dec16 = Bind(), _dec17 = Bind(), _dec18 = Bind(), _dec19 = Bind(), _dec20 = Bind(), _dec21 = Bind(), _dec22 = Bind(), _dec23 = Bind(), _dec24 = Bind(), _dec25 = Bind(), _dec26 = Bind(), _dec27 = Bind(), _dec28 = Bind(), _dec29 = Bind(), _dec30 = Bind(), _dec31 = Bind(), _dec32 = Bind(), _dec33 = Bind(), _dec34 = Bind(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_React$Component) {
  _inherits(SubAccountSite, _React$Component);

  var _super = _createSuper(SubAccountSite);

  function SubAccountSite() {
    var _this;

    _classCallCheck(this, SubAccountSite);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _super.call.apply(_super, [this].concat(args));
    _this.filterFormRef = void 0;
    _this.state = {
      editPasswordModalProps: {},
      editModalProps: {},
      groupModalProps: {},
      createPasswordRuleData: {},
      // pagination: false,
      // 导出相关
      // expandedKeys: [],
      // checkedKeys: [],
      employeeVisible: false,
      currentUserId: ''
    };
    return _this;
  }

  _createClass(SubAccountSite, [{
    key: "componentDidMount",
    value: function componentDidMount() {
      this.handleFetchList();
      var dispatch = this.props.dispatch;
      dispatch({
        type: 'subAccount/init'
      }); // 获取公钥

      dispatch({
        type: 'subAccount/getPublicKey'
      });
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props = this.props,
          _this$props$subAccoun = _this$props.subAccount,
          _this$props$subAccoun2 = _this$props$subAccoun.publicKey,
          publicKey = _this$props$subAccoun2 === void 0 ? '' : _this$props$subAccoun2,
          _this$props$subAccoun3 = _this$props$subAccoun.passwordTipMsg,
          passwordTipMsg = _this$props$subAccoun3 === void 0 ? {} : _this$props$subAccoun3,
          _this$props$subAccoun4 = _this$props$subAccoun.pagination,
          pagination = _this$props$subAccoun4 === void 0 ? false : _this$props$subAccoun4,
          _this$props$subAccoun5 = _this$props$subAccoun.dataSource,
          dataSource = _this$props$subAccoun5 === void 0 ? [] : _this$props$subAccoun5,
          _this$props$subAccoun6 = _this$props$subAccoun.lov;
      _this$props$subAccoun6 = _this$props$subAccoun6 === void 0 ? {} : _this$props$subAccoun6;
      var level = _this$props$subAccoun6.level,
          levelMap = _this$props$subAccoun6.levelMap,
          idd = _this$props$subAccoun6.idd,
          gender = _this$props$subAccoun6.gender,
          _this$props$subAccoun7 = _this$props$subAccoun6.userType,
          userType = _this$props$subAccoun7 === void 0 ? [] : _this$props$subAccoun7,
          _this$props$subAccoun8 = _this$props$subAccoun.employeeList,
          employeeList = _this$props$subAccoun8 === void 0 ? [] : _this$props$subAccoun8,
          _this$props$subAccoun9 = _this$props$subAccoun.employeePagination,
          employeePagination = _this$props$subAccoun9 === void 0 ? {} : _this$props$subAccoun9,
          _this$props$passwordL = _this$props.passwordLoading,
          passwordLoading = _this$props$passwordL === void 0 ? false : _this$props$passwordL,
          _this$props$queryDeta = _this$props.queryDetailLoading,
          queryDetailLoading = _this$props$queryDeta === void 0 ? false : _this$props$queryDeta,
          _this$props$roleRemov = _this$props.roleRemoveLoading,
          roleRemoveLoading = _this$props$roleRemov === void 0 ? false : _this$props$roleRemov,
          fetching = _this$props.fetching,
          saving = _this$props.saving,
          _this$props$currentUs = _this$props.currentUser,
          currentUser = _this$props$currentUs === void 0 ? {} : _this$props$currentUs,
          path = _this$props.match.path,
          fetchEmployeeLoading = _this$props.fetchEmployeeLoading;
      var _this$state = this.state,
          _this$state$editPassw = _this$state.editPasswordModalProps,
          editPasswordModalProps = _this$state$editPassw === void 0 ? {} : _this$state$editPassw,
          _this$state$editModal = _this$state.editModalProps,
          editModalProps = _this$state$editModal === void 0 ? {} : _this$state$editModal,
          _this$state$groupModa = _this$state.groupModalProps,
          groupModalProps = _this$state$groupModa === void 0 ? {} : _this$state$groupModa,
          _this$state$editRecor = _this$state.editRecord,
          editRecord = _this$state$editRecor === void 0 ? {} : _this$state$editRecor,
          _this$state$createPas = _this$state.createPasswordRuleData,
          createPasswordRuleData = _this$state$createPas === void 0 ? {} : _this$state$createPas,
          employeeVisible = _this$state.employeeVisible;
      return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Header, {
        title: intl.get('ciam.subAccount.view.message.title').d('子账户管理')
      }, /*#__PURE__*/React.createElement(ButtonPermission, {
        permissionList: [{
          code: "".concat(path, ".button.create"),
          type: 'button',
          meaning: '子账户管理-新建'
        }],
        type: "primary",
        onClick: this.showCreateForm,
        icon: "plus"
      }, intl.get('cpaas.common.button.create').d('新建')), /*#__PURE__*/React.createElement(ExcelExport, {
        exportAsync: true,
        requestUrl: "".concat(CPAAS_IAM, "/cpaas/v1/users/export"),
        queryParams: this.getExportQueryParams(),
        queryFormItem: this.renderExportTree()
      })), /*#__PURE__*/React.createElement(Content, null, /*#__PURE__*/React.createElement("div", {
        className: classnames('table-list-form', 'table-list-search')
      }, /*#__PURE__*/React.createElement(FilterForm, {
        onRef: this.handleFilterFormRef,
        onSearch: this.handleFetchList,
        userType: userType
      })), /*#__PURE__*/React.createElement(Table, {
        bordered: true,
        pagination: pagination,
        dataSource: dataSource,
        loading: fetching || queryDetailLoading,
        onChange: this.handleTableChange,
        columns: this.getColumns(),
        scroll: {
          x: tableScrollWidth(this.getColumns())
        },
        rowKey: "id"
      })), editPasswordModalProps.visible && /*#__PURE__*/React.createElement(EditPasswordModal, Object.assign({
        editRecord: editRecord,
        publicKey: publicKey,
        passwordTipMsg: passwordTipMsg,
        key: "edit-modal-password"
      }, editPasswordModalProps, {
        onCancel: this.handlePasswordModalHidden,
        onOk: this.handlePasswordUpdate,
        confirmLoading: passwordLoading
      })), editModalProps.visible && /*#__PURE__*/React.createElement(EditModal, Object.assign({
        key: "edit-modal",
        passwordTipMsg: createPasswordRuleData,
        getPasswordRule: this.handlePasswordRule
      }, editModalProps, {
        currentUser: currentUser,
        fetchDetailData: this.fetchDetailData,
        onCancel: this.hiddenEditModal,
        onOk: this.handleEditModalOK,
        getCurrentUserRoles: this.getCurrentUserRoles,
        path: path,
        level: level,
        levelMap: levelMap,
        idd: idd,
        userType: userType,
        gender: gender,
        fetchRoles: this.fetchRoles,
        fetchCurrentUserRoles: this.fetchCurrentUserRoles,
        onRoleRemove: this.handleRoleRemove,
        confirmLoading: saving,
        queryDetailLoading: queryDetailLoading,
        roleRemoveLoading: roleRemoveLoading
      })), groupModalProps.visible && /*#__PURE__*/React.createElement(UserGroupModal, Object.assign({
        key: "group-modal"
      }, groupModalProps, {
        path: path,
        onCancel: this.hiddenGroupModal,
        onOk: this.handleGroupModalOK,
        fetchGroups: this.fetchGroups,
        fetchCurrentUserGroups: this.fetchCurrentUserGroups,
        onGroupRemove: this.handleGroupRemove
      })), /*#__PURE__*/React.createElement(EmployeeModal, {
        key: "employee",
        path: path,
        dataSource: employeeList,
        pagination: employeePagination,
        visible: employeeVisible,
        onCancel: this.hiddenEmployeeModal,
        onSearch: this.handleQueryEmployee,
        onTableChange: this.handleEmployeeTableChange,
        fetchEmployeeLoading: fetchEmployeeLoading
      }));
    }
  }, {
    key: "hiddenEmployeeModal",
    value: function hiddenEmployeeModal() {
      this.setState({
        employeeVisible: false
      });
    }
  }, {
    key: "handleQueryEmployee",
    value: function handleQueryEmployee() {
      var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
      var dispatch = this.props.dispatch;
      var currentUserId = this.state.currentUserId;
      dispatch({
        type: 'subAccount/queryEmployee',
        payload: _objectSpread({
          userId: currentUserId
        }, params)
      });
    }
  }, {
    key: "handleEmployeeTableChange",
    value: function handleEmployeeTableChange() {
      var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
      var dispatch = this.props.dispatch;
      var currentUserId = this.state.currentUserId;
      dispatch({
        type: 'subAccount/queryEmployee',
        payload: _objectSpread({
          userId: currentUserId
        }, params)
      });
    }
  }, {
    key: "handlePasswordRule",
    value: function handlePasswordRule(id) {
      var _this2 = this;

      var dispatch = this.props.dispatch;
      dispatch({
        type: 'subAccount/getPasswordRule',
        payload: {
          organizationId: id
        }
      }).then(function (res) {
        if (res) {
          _this2.setState({
            createPasswordRuleData: res
          });
        }
      });
    }
    /**
     * 拿到查询表单的引用
     * @param {object} filterFormRef
     */

  }, {
    key: "handleFilterFormRef",
    value: function handleFilterFormRef(filterFormRef) {
      this.filterFormRef = filterFormRef;
    }
    /**
     * 查询账号信息
     * @param {object} pagination
     */

  }, {
    key: "handleFetchList",
    value: function handleFetchList(pagination) {
      this.setState({
        pagination: pagination
      });
      var dispatch = this.props.dispatch;
      var fieldsValue = {};

      if (this.filterFormRef) {
        var form = this.filterFormRef.props.form;
        fieldsValue = form.getFieldsValue();
        fieldsValue.startDateActive = fieldsValue.startDateActive ? fieldsValue.startDateActive.format(DEFAULT_DATE_FORMAT) : undefined;
        fieldsValue.endDateActive = fieldsValue.endDateActive ? fieldsValue.endDateActive.format(DEFAULT_DATE_FORMAT) : undefined;
      }

      dispatch({
        type: 'subAccount/fetchSubAccountList',
        payload: _objectSpread(_objectSpread({}, pagination), fieldsValue)
      });
    }
    /**
     * 从新加载页面，保留分页信息
     */

  }, {
    key: "reloadList",
    value: function reloadList() {
      var pagination = this.state.pagination;
      this.handleFetchList(pagination);
    }
    /**
     * 页码改变
     * @param {object} page
     * @param {object} filter
     * @param {object} sort
     */

  }, {
    key: "handleTableChange",
    value: function handleTableChange(page, filter, sort) {
      this.handleFetchList({
        page: page,
        sort: sort
      });
    }
  }, {
    key: "handleViewEmployee",
    value: function handleViewEmployee(record) {
      var dispatch = this.props.dispatch;
      this.setState({
        employeeVisible: true,
        currentUserId: record.id
      });
      dispatch({
        type: 'subAccount/queryEmployee',
        payload: {
          userId: record.id
        }
      });
    }
  }, {
    key: "getColumns",
    value: function getColumns() {
      var _this3 = this;

      var _this$props2 = this.props,
          currentUserId = _this$props2.currentUserId,
          path = _this$props2.match.path;
      return [{
        title: intl.get('ciam.subAccount.model.user.loginName').d('账号'),
        dataIndex: 'loginName',
        width: 120
      }, {
        title: intl.get('ciam.subAccount.model.user.realName').d('名称'),
        dataIndex: 'realName' // width: 220,

      }, {
        title: intl.get('ciam.subAccount.model.user.email').d('邮箱'),
        dataIndex: 'email',
        width: 300
      }, {
        title: intl.get('ciam.subAccount.model.user.phone').d('手机号码'),
        dataIndex: 'phone',
        width: 200,
        render: function render(phone, record) {
          if (record.internationalTelMeaning && record.phone) {
            // todo 需要改成好看的样子
            return "".concat(record.internationalTelMeaning, " | ").concat(record.phone);
          }

          return phone;
        }
      }, {
        title: intl.get('cpaas.common.date.active.from').d('有效日期从'),
        dataIndex: 'startDateActive',
        width: 120,
        render: dateRender
      }, {
        title: intl.get('cpaas.common.date.active.to').d('有效日期至'),
        dataIndex: 'endDateActive',
        width: 120,
        render: dateRender
      }, {
        title: intl.get('ciam.subAccount.model.user.enabled').d('冻结'),
        dataIndex: 'enabled',
        width: 80,
        render: function render(item) {
          return /*#__PURE__*/React.createElement(Badge, {
            status: item === true ? 'success' : 'error',
            text: item === false ? intl.get('cpaas.common.status.yes').d('是') : intl.get('cpaas.common.status.no').d('否')
          });
        }
      }, {
        title: intl.get('ciam.subAccount.model.user.locked').d('锁定'),
        dataIndex: 'locked',
        width: 80,
        render: function render(item) {
          return /*#__PURE__*/React.createElement(Badge, {
            status: item === false ? 'success' : 'error',
            text: item === true ? intl.get('cpaas.common.status.yes').d('是') : intl.get('cpaas.common.status.no').d('否')
          });
        }
      }, {
        title: intl.get('ciam.subAccount.model.user.userType').d('用户类型'),
        dataIndex: 'userTypeMeaning',
        width: 90
      }, {
        title: intl.get('ciam.subAccount.model.user.tenant').d('所属租户'),
        dataIndex: 'tenantName',
        width: 200
      }, {
        title: intl.get('cpaas.common.button.action').d('操作'),
        key: 'edit',
        width: 200,
        fixed: 'right',
        render: function render(text, record) {
          var _record$admin = record.admin,
              admin = _record$admin === void 0 ? false : _record$admin;
          var operators = [{
            key: 'edit',
            ele: /*#__PURE__*/React.createElement(ButtonPermission, {
              type: "text",
              permissionList: [{
                code: "".concat(path, ".button.edit"),
                type: 'button',
                meaning: '子账户管理-编辑'
              }],
              key: "edit",
              onClick: function onClick() {
                _this3.showEditModal(record);
              }
            }, intl.get('cpaas.common.button.edit').d('编辑')),
            len: 2,
            title: intl.get('cpaas.common.button.edit').d('编辑')
          }, {
            key: 'password',
            ele: admin || record.id === currentUserId ? null : /*#__PURE__*/React.createElement(ButtonPermission, {
              type: "text",
              permissionList: [{
                code: "".concat(path, ".button.password"),
                type: 'button',
                meaning: '子账户管理-修改密码'
              }],
              key: "password",
              onClick: function onClick() {
                _this3.handleRecordUpdatePassword(record);
              }
            }, intl.get('ciam.subAccount.view.option.passwordUpdate').d('修改密码')),
            len: 4,
            title: intl.get('ciam.subAccount.view.option.passwordUpdate').d('修改密码')
          }, {
            key: 'unlock',
            ele: record.locked && /*#__PURE__*/React.createElement(ButtonPermission, {
              type: "text",
              permissionList: [{
                code: "".concat(path, ".button.unlock"),
                type: 'button',
                meaning: '子账户管理-解除锁定'
              }],
              key: "unlock",
              onClick: function onClick() {
                _this3.handleUnlock(record);
              }
            }, intl.get('ciam.subAccount.view.option.unlock').d('解除锁定')),
            len: 4,
            title: intl.get('ciam.subAccount.view.option.unlock').d('解除锁定')
          }];
          return operatorRender(operators);
        }
      }];
    }
    /**
     * 打开密码编辑模态框
     * @param {object} editRecord
     */

  }, {
    key: "handleRecordUpdatePassword",
    value: function handleRecordUpdatePassword(editRecord) {
      var dispatch = this.props.dispatch;
      this.setState({
        editPasswordModalProps: {
          visible: true,
          editRecord: editRecord
        }
      });
      dispatch({
        type: 'subAccount/getPasswordRule',
        payload: {
          organizationId: editRecord.organizationId
        }
      });
    }
    /**
     * 隐藏密码模态框
     */

  }, {
    key: "handlePasswordModalHidden",
    value: function handlePasswordModalHidden() {
      this.setState({
        editPasswordModalProps: {
          visible: false
        }
      });
    }
    /**
     * 更新密码
     * @param {object} fieldsValue
     */

  }, {
    key: "handlePasswordUpdate",
    value: function handlePasswordUpdate(fieldsValue) {
      var _this4 = this;

      var dispatch = this.props.dispatch;
      var _this$state$editPassw2 = this.state.editPasswordModalProps.editRecord,
          editRecord = _this$state$editPassw2 === void 0 ? {} : _this$state$editPassw2;
      var id = editRecord.id,
          organizationId = editRecord.organizationId;
      dispatch({
        type: 'subAccount/updatePassword',
        payload: _objectSpread({
          userId: id,
          userOrganizationId: organizationId
        }, fieldsValue)
      }).then(function (res) {
        if (res) {
          notification.success();

          _this4.handlePasswordModalHidden();
        }
      });
    }
    /**
     * 打开新建模态框
     */

  }, {
    key: "showCreateForm",
    value: function showCreateForm() {
      var _this$props$user$curr = this.props.user.currentUser;
      _this$props$user$curr = _this$props$user$curr === void 0 ? {} : _this$props$user$curr;
      var organizationId = _this$props$user$curr.organizationId;
      this.handlePasswordRule(organizationId);
      this.setState({
        editModalProps: {
          visible: true,
          isCreate: true,
          isAdmin: false
        }
      });
    }
  }, {
    key: "fetchDetailData",
    value: function fetchDetailData(record) {
      var _this5 = this;

      var dispatch = this.props.dispatch;
      return dispatch({
        type: 'subAccount/querySubAccount',
        payload: {
          userId: record.id
        }
      }).then(function (editRecord) {
        var editModalProps = _this5.state.editModalProps;

        _this5.setState({
          editModalProps: _objectSpread(_objectSpread({}, editModalProps), {}, {
            editRecord: editRecord
          })
        });

        return editRecord;
      });
    }
    /**
     * 编辑账号
     * 打开账号模态框
     * @param {object} editRecord
     */

  }, {
    key: "showEditModal",
    value: function showEditModal(editRecord) {
      this.setState({
        editModalProps: {
          visible: true,
          isCreate: false,
          isAdmin: editRecord.admin,
          detailRecord: editRecord
        }
      });
    }
    /**
     * 分配用户组
     * 打开用户组弹窗
     * @param {object} userRecord
     */

  }, {
    key: "showGroupModal",
    value: function showGroupModal(userRecord) {
      this.setState({
        groupModalProps: {
          visible: true,
          isCreate: false,
          userRecord: userRecord
        }
      });
    }
    /**
     * 关闭用户组模态框
     */

  }, {
    key: "hiddenGroupModal",
    value: function hiddenGroupModal() {
      this.setState({
        groupModalProps: {
          visible: false
        }
      });
    }
    /**
     * 获取已经分配的角色
     * @param {object} payload
     * @param {number} payload.userId 当前编辑账号id
     * @param {pagination} payload.pagination 分页信息
     */

  }, {
    key: "fetchCurrentUserRoles",
    value: function fetchCurrentUserRoles(payload) {
      var dispatch = this.props.dispatch;
      return dispatch({
        type: 'subAccount/getCurrentUserRoles',
        payload: payload
      });
    } // TODO接口联调

    /**
     * 获取已经分配的用户组
     * @param {object} payload
     * @param {number} payload.userId 当前编辑账号id
     * @param {pagination} payload.pagination 分页信息
     */

  }, {
    key: "fetchCurrentUserGroups",
    value: function fetchCurrentUserGroups(payload) {
      var dispatch = this.props.dispatch;
      return dispatch({
        type: 'subAccount/getCurrentUserGroups',
        payload: payload
      });
    }
    /**
     * 关闭编辑模态框
     */

  }, {
    key: "hiddenEditModal",
    value: function hiddenEditModal() {
      this.setState({
        editModalProps: {
          visible: false
        }
      });
    }
    /**
     * 保存 新建账号 或 更新账号
     * @param saveData
     */

  }, {
    key: "handleEditModalOK",
    value: function handleEditModalOK(saveData) {
      var _this6 = this;

      var _this$props3 = this.props,
          dispatch = _this$props3.dispatch,
          publicKey = _this$props3.subAccount.publicKey;
      var _this$state$editModal2 = this.state.editModalProps.isCreate,
          isCreate = _this$state$editModal2 === void 0 ? true : _this$state$editModal2;

      if (isCreate) {
        dispatch({
          type: 'subAccount/createSubAccount',
          payload: _objectSpread(_objectSpread({}, saveData), {}, {
            password: saveData.password ? encryptPwd(saveData.password, publicKey) : undefined
          })
        }).then(function (res) {
          if (res) {
            notification.success();

            _this6.hiddenEditModal();

            _this6.reloadList();
          }
        });
      } else {
        dispatch({
          type: 'subAccount/updateSubAccount',
          payload: saveData
        }).then(function (res) {
          if (res) {
            notification.success();

            _this6.hiddenEditModal();

            _this6.reloadList();
          }
        });
      }
    }
    /**
     * 保存 用户组信息
     * @param saveData
     */

  }, {
    key: "handleGroupModalOK",
    value: function handleGroupModalOK(saveData) {
      var _this7 = this;

      var dispatch = this.props.dispatch;
      dispatch({
        type: 'subAccount/addUserGroup',
        payload: saveData
      }).then(function (res) {
        if (res) {
          notification.success();

          _this7.hiddenGroupModal();

          _this7.reloadList();
        }
      });
    }
    /**
     * 解锁账号
     * @param {object} unLockRecord
     */

  }, {
    key: "handleUnlock",
    value: function handleUnlock(unLockRecord) {
      var _this8 = this;

      var dispatch = this.props.dispatch;
      return dispatch({
        type: 'subAccount/unlockSubAccount',
        payload: {
          userId: unLockRecord.id
        }
      }).then(function (res) {
        if (res) {
          _this8.reloadList();
        }
      });
    }
    /**
     * 查询 可分配角色
     * @param {object} params
     */

  }, {
    key: "fetchRoles",
    value: function fetchRoles(params) {
      var dispatch = this.props.dispatch;
      return dispatch({
        type: 'subAccount/fetchRoles',
        payload: params
      });
    } // TODO 接口

    /**
     * 查询 可分配的用户组
     * @param {object} params
     */

  }, {
    key: "fetchGroups",
    value: function fetchGroups(params) {
      var dispatch = this.props.dispatch;
      return dispatch({
        type: 'subAccount/fetchGroups',
        payload: params
      });
    }
    /**
     * 删除角色
     * @param {object[]} memberRoleList
     */

  }, {
    key: "handleRoleRemove",
    value: function handleRoleRemove(memberRoleList) {
      var dispatch = this.props.dispatch;
      return dispatch({
        type: 'subAccount/removeRoles',
        payload: {
          memberRoleList: memberRoleList
        }
      });
    } // TODO 接口

    /**
     * 删除用户组
     * @param {object[]} params
     */

  }, {
    key: "handleGroupRemove",
    value: function handleGroupRemove(params) {
      var dispatch = this.props.dispatch;
      return dispatch({
        type: 'subAccount/deleteUserGroup',
        payload: params
      });
    } // 导出

    /**
     * 获取导出字段查询参数
     */

  }, {
    key: "getExportQueryParams",
    value: function getExportQueryParams() {
      var checkedKeys = this.state.checkedKeys;
      var fieldsValue = {};

      if (this.filterFormRef) {
        fieldsValue = this.filterFormRef.props.form.getFieldsValue();
        fieldsValue.startDateActive = fieldsValue.startDateActive ? fieldsValue.startDateActive.format(DEFAULT_DATE_FORMAT) : undefined;
        fieldsValue.endDateActive = fieldsValue.endDateActive ? fieldsValue.endDateActive.format(DEFAULT_DATE_FORMAT) : undefined;
      }

      return _objectSpread(_objectSpread({}, fieldsValue), {}, {
        authorityTypeQueryParams: _join(checkedKeys, ',')
      });
    }
    /**
     * 节点展开
     * @param {string[]} expandedKeys - 展开的节点组成的数组
     */

  }, {
    key: "handleExpand",
    value: function handleExpand(expandedKeys) {
      this.setState({
        expandedKeys: expandedKeys
      });
    }
    /**
     * 选择项变化监控
     * @param {string[]} checkedKeys - 选中项的 key 数组
     */

  }, {
    key: "handleSelect",
    value: function handleSelect(checkedKeys) {
      this.setState({
        checkedKeys: checkedKeys
      });
    }
    /**
     * 渲染权限维度的树
     */

  }, {
    key: "renderExportTree",
    value: function renderExportTree() {
      var _this$props$subAccoun10 = this.props.subAccount.dimensionList,
          dimensionList = _this$props$subAccoun10 === void 0 ? [] : _this$props$subAccoun10;
      var _this$state2 = this.state,
          expandedKeys = _this$state2.expandedKeys,
          checkedKeys = _this$state2.checkedKeys;

      if (_isEmpty(dimensionList)) {
        return null;
      } else {
        return /*#__PURE__*/React.createElement(Tree, {
          checkable: true,
          onExpand: this.handleExpand,
          expandedKeys: expandedKeys,
          defaultExpandedKeys: ['authorityType'],
          onCheck: this.handleSelect,
          checkedKeys: checkedKeys
        }, /*#__PURE__*/React.createElement(TreeNode, {
          title: intl.get('ciam.subAccount.model.user.authorityType').d('权限维度'),
          key: "authorityType"
        }, _map(dimensionList, function (item) {
          return /*#__PURE__*/React.createElement(TreeNode, {
            title: item.dimensionName,
            key: item.dimensionCode
          });
        })));
      }
    }
  }]);

  return SubAccountSite;
}(React.Component), (_applyDecoratedDescriptor(_class2.prototype, "hiddenEmployeeModal", [_dec3], Object.getOwnPropertyDescriptor(_class2.prototype, "hiddenEmployeeModal"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleQueryEmployee", [_dec4], Object.getOwnPropertyDescriptor(_class2.prototype, "handleQueryEmployee"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleEmployeeTableChange", [_dec5], Object.getOwnPropertyDescriptor(_class2.prototype, "handleEmployeeTableChange"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handlePasswordRule", [_dec6], Object.getOwnPropertyDescriptor(_class2.prototype, "handlePasswordRule"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleFilterFormRef", [_dec7], Object.getOwnPropertyDescriptor(_class2.prototype, "handleFilterFormRef"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleFetchList", [_dec8], Object.getOwnPropertyDescriptor(_class2.prototype, "handleFetchList"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "reloadList", [_dec9], Object.getOwnPropertyDescriptor(_class2.prototype, "reloadList"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleTableChange", [_dec10], Object.getOwnPropertyDescriptor(_class2.prototype, "handleTableChange"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleViewEmployee", [_dec11], Object.getOwnPropertyDescriptor(_class2.prototype, "handleViewEmployee"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "getColumns", [_dec12], Object.getOwnPropertyDescriptor(_class2.prototype, "getColumns"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleRecordUpdatePassword", [_dec13], Object.getOwnPropertyDescriptor(_class2.prototype, "handleRecordUpdatePassword"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handlePasswordModalHidden", [_dec14], Object.getOwnPropertyDescriptor(_class2.prototype, "handlePasswordModalHidden"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handlePasswordUpdate", [_dec15], Object.getOwnPropertyDescriptor(_class2.prototype, "handlePasswordUpdate"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "showCreateForm", [_dec16], Object.getOwnPropertyDescriptor(_class2.prototype, "showCreateForm"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "fetchDetailData", [_dec17], Object.getOwnPropertyDescriptor(_class2.prototype, "fetchDetailData"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "showEditModal", [_dec18], Object.getOwnPropertyDescriptor(_class2.prototype, "showEditModal"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "showGroupModal", [_dec19], Object.getOwnPropertyDescriptor(_class2.prototype, "showGroupModal"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "hiddenGroupModal", [_dec20], Object.getOwnPropertyDescriptor(_class2.prototype, "hiddenGroupModal"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "fetchCurrentUserRoles", [_dec21], Object.getOwnPropertyDescriptor(_class2.prototype, "fetchCurrentUserRoles"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "fetchCurrentUserGroups", [_dec22], Object.getOwnPropertyDescriptor(_class2.prototype, "fetchCurrentUserGroups"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "hiddenEditModal", [_dec23], Object.getOwnPropertyDescriptor(_class2.prototype, "hiddenEditModal"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleEditModalOK", [_dec24], Object.getOwnPropertyDescriptor(_class2.prototype, "handleEditModalOK"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleGroupModalOK", [_dec25], Object.getOwnPropertyDescriptor(_class2.prototype, "handleGroupModalOK"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleUnlock", [_dec26], Object.getOwnPropertyDescriptor(_class2.prototype, "handleUnlock"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "fetchRoles", [_dec27], Object.getOwnPropertyDescriptor(_class2.prototype, "fetchRoles"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "fetchGroups", [_dec28], Object.getOwnPropertyDescriptor(_class2.prototype, "fetchGroups"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleRoleRemove", [_dec29], Object.getOwnPropertyDescriptor(_class2.prototype, "handleRoleRemove"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleGroupRemove", [_dec30], Object.getOwnPropertyDescriptor(_class2.prototype, "handleGroupRemove"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "getExportQueryParams", [_dec31], Object.getOwnPropertyDescriptor(_class2.prototype, "getExportQueryParams"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleExpand", [_dec32], Object.getOwnPropertyDescriptor(_class2.prototype, "handleExpand"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleSelect", [_dec33], Object.getOwnPropertyDescriptor(_class2.prototype, "handleSelect"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "renderExportTree", [_dec34], Object.getOwnPropertyDescriptor(_class2.prototype, "renderExportTree"), _class2.prototype)), _class2)) || _class) || _class);
export { SubAccountSite as default };